/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.repository.common;

import com.inspur.edp.cef.api.attr.CefDataAttribute;
import com.inspur.edp.cef.api.attr.CefEntityAttribute;
import com.inspur.edp.cef.generator.overall.GeneratorUtil;

import java.lang.reflect.Constructor;

public class CefMgrTypeInfo {
	private CompileContext compileContext;
	public CefMgrTypeInfo() {
		privateEntityEntityTypeInfos = new java.util.HashMap<String, CefEntityTypeInfo>();
	}

	public CefMgrTypeInfo(CompileContext compileContext) {
		this.compileContext = compileContext;
		privateEntityEntityTypeInfos = new java.util.HashMap<String, CefEntityTypeInfo>();
	}

	private CefEntityTypeInfo entityEntityTypeInfo;

	public final CefEntityTypeInfo getEntityEntityTypeInfo() {
		if (entityEntityTypeInfo == null) {
			entityEntityTypeInfo = new CefEntityTypeInfo();
		}
		return entityEntityTypeInfo;
	}

	private java.util.HashMap<String, CefEntityTypeInfo> privateEntityEntityTypeInfos;

	public final java.util.HashMap<String, CefEntityTypeInfo> getEntityEntityTypeInfos() {
		return privateEntityEntityTypeInfos;
	}

	public final void getEntityEntityTypeInfos(java.util.HashMap<String, CefEntityTypeInfo> value) {
		privateEntityEntityTypeInfos = value;
	}

	public final void addEntityAllInterfaceType(String nodeCode, Class allInterfaceType) {
		getOrCreateNodeType(nodeCode).setAllInterfaceType(allInterfaceType);
	}

	public final void addEntityActionImplType(String nodeCode, Class implType) {
		getOrCreateNodeType(nodeCode).setActionImplType(implType);
	}

	public final void addEntityDataInterfaceType(String nodeCode, Class dataInterfaceType) {
		getOrCreateNodeType(nodeCode).setDataInterfaceType(dataInterfaceType);
	}

	public final void addEntityActionInterfaceType(String nodeCode, Class actionInterfaceType) {
		getOrCreateNodeType(nodeCode).setActionInterfaceType(actionInterfaceType);
	}

	public final void addEntityGeneratedImplType(String nodeCode, Class type) {
		getOrCreateNodeType(nodeCode).setGeneratedImplType(type);
	}

	private CefEntityTypeInfo getOrCreateNodeType(String nodeCode) {
		if (getEntityEntityTypeInfos().containsKey(nodeCode)) {
			return getEntityEntityTypeInfos().get(nodeCode);
		}
		CefEntityTypeInfo info = new CefEntityTypeInfo();
		getEntityEntityTypeInfos().put(nodeCode, info);
		return info;
	}

	///#endregion

	private Class privateInterfaceType;

	public final Class getInterfaceType() {
		return privateInterfaceType;
	}

	public final void setInterfaceType(Class value) {
		privateInterfaceType = value;
	}

	private Class privateAllInterfaceType;

	public final Class getAllInterfaceType() {
		return privateAllInterfaceType;
	}

	public final void setAllInterfaceType(Class value) {
		privateAllInterfaceType = value;
	}

	private Class privateGeneratedImplType;

	public final Class getGeneratedImplType() {
		return privateGeneratedImplType;
	}

	public final void setGeneratedImplType(Class value) {
		privateGeneratedImplType = value;
	}

	private Class implType;

	public Class getImplType() {
		return implType;
	}

	public final void setImplType(Class value) {
		implType = value;
		CefEntityAttribute mgrAttribute = (CefEntityAttribute) getImplType().<CefEntityAttribute>getAnnotation(CefEntityAttribute.class);
		//TODO 确认：基类上（类似beManager）是否有标签
		if (mgrAttribute != null) {
			CefEntityTypeInfo tempVar = new CefEntityTypeInfo();
//			tempVar.setActionInterfaceType(GeneratorUtil.getType(compileContext,mgrAttribute.entityActionType().getTypeName()));
//			tempVar.setActionImplType(GeneratorUtil.getType(compileContext,mgrAttribute.entityActionImplType().getTypeName()));
//			tempVar.setAllInterfaceType(GeneratorUtil.getType(compileContext,mgrAttribute.entityAllType().getTypeName()));
			entityEntityTypeInfo = tempVar;
		}

		CefDataAttribute dataAttribute = (CefDataAttribute) getImplType().<CefDataAttribute>getAnnotation(CefDataAttribute.class);
		if (dataAttribute != null) {
//			getEntityEntityTypeInfo().setDataInterfaceType(
//					GeneratorUtil.getType(compileContext,dataAttribute.dataInterfaceType().getTypeName()));
		}

	}


	private Class privateAssemblerType;

	public final Class getAssemblerType() {
		return privateAssemblerType;
	}

	public final void setAssemblerType(Class value) {
		privateAssemblerType = value;
	}

	//TODO 持久化层生成后赋值
	private Class privateGeneratedRepositoryType;

	public final Class getGeneratedRepositoryType() {
		return privateGeneratedRepositoryType;
	}

	public final void setGeneratedRepositoryType(Class value) {
		privateGeneratedRepositoryType = value;
	}

	private java.util.List<Byte[]> privateAssemblyRaw = new java.util.ArrayList<Byte[]>();

	public final java.util.List<Byte[]> getAssemblyRaw() {
		return privateAssemblyRaw;
	}


	private CefMgrTypeInfo privateVariableInfo;

	public final CefMgrTypeInfo getVariableInfo() {
		return privateVariableInfo;
	}

	public final void setVariableInfo(CefMgrTypeInfo value) {
		privateVariableInfo = value;
	}

	private Constructor mgrConstructor;

	public Constructor getMgrConstructor() {
		return mgrConstructor;
	}

	public void setMgrConstructor(Constructor mgrConstructor) {
		this.mgrConstructor = mgrConstructor;
	}
}
